package com.example.demo.controller;
import com.example.demo.common.Result;
import com.example.demo.entity.Staff;
import com.example.demo.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;

    @GetMapping("/list")
    public List<Staff> list() {
        return staffService.list();
    }

    @PostMapping("/save")
    public Result save(@RequestBody Staff staff) {
        return staffService.save(staff) ? Result.suc() : Result.fail();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Staff staff) {
        return staffService.updateById(staff) ? Result.suc() : Result.fail();
    }

    @GetMapping("/del")
    public Result del(@RequestParam Integer id) {
        return staffService.removeById(id) ? Result.suc() : Result.fail();
    }

    @PostMapping("/mod")
    public boolean mod(@RequestBody Staff staff) {
        return staffService.updateById(staff);
    }

    @PostMapping("/saveOrMod")
    public boolean saveOrMod(@RequestBody Staff staff) {
        return staffService.saveOrUpdate(staff);
    }
}

